package com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.service.impl;

import com.learn.springcloud.hystrixexplainindetailconsumer.bean.User;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.service.RequestCollapserAnnotationService;
import com.learn.springcloud.hystrixexplainindetailconsumer.request.collapser.service.RequestCollapserExtendService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 使用注解方式实现请求合并
 * @Time : 2018/8/6 20:16
 * @Version : 1.0
 */
@Service
public class RequestCollapserAnnotationServiceImpl implements RequestCollapserAnnotationService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    @HystrixCollapser(batchMethod = "finds", collapserProperties = {
            @HystrixProperty(name = "timerDelayInMilliseconds", value = "100")
    })
    public User find(Long id) {
        System.out.println(id);
        return restTemplate.getForObject("http://hystrix-explain-in-detail-provider/request/collpaser/find/user/{1}", User.class, id);
    }

    @Override
    @HystrixCommand
    public List<User> finds(List<Long> ids) {
        return null;
    }
}
